﻿using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using SimpleTicketBooking.Controllers.Base;
using SimpleTicketBooking.Models;
using SimpleTicketBooking.Models.Request;
using SimpleTicketBooking.Utils.Ext;
using System.ComponentModel;

namespace SimpleTicketBooking.Controllers
{
    /// <summary>
    /// Ticket Booking Resources
    /// </summary>
    [ApiVersion((double)ApiVersions.V1)]
    [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
    [ApiController]
    [Route("api/[controller]/v{version:apiVersion}/[action]")]
    public class BookingController : APIControllerBase
    {
        private readonly ILogger<BookingController> _logger;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logger"></param>
        public BookingController(ILogger<BookingController> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// Book ticket
        /// </summary>
        /// <param name="bookRequest"></param>
        /// <returns></returns>
        [HttpPost(Name ="Book")]
        [Description("Should return the booking order details to user after the booking order created")]
        public Order Book(BookingRequest bookRequest)
        {
            // need transaction to keep ACID for creating Order and tickets

            return new Order
            {
                Id = 1,
                EventId = bookRequest.EventId,
                Quantity = bookRequest.Quantity,
                Status = OrderStatus.Unpaid,
                IsDeleted = false,
                TotalPrice = 100,
                UserId = GetUserId(),
                UpdatedTime = DateTime.Now,
                CreatedTime = DateTime.Now,
            };
        }

        /// <summary>
        /// pay Order 
        /// </summary>
        /// <param name="OrderId"></param>
        /// <returns></returns>
        [HttpPost(Name = "Pay")]
        [Description("Should return the booking order details to user after the booking order paid")]
        public Order Pay(int OrderId)
        {
            // need transaction to keep ACID for creating Order and tickets

            return new Order
            {
                Id = 1,
                EventId = 1,
                Quantity = 3,
                Status = OrderStatus.paid,
                IsDeleted = false,
                TotalPrice = 100,
                UserId = GetUserId(),
                UpdatedTime = DateTime.Now,
                CreatedTime = DateTime.Now,
            };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [HttpPost(Name = "Cancel")]

        [Description("Should return the booking order details to user after the booking order cancelled")]
        public Order Cancel(int orderId)
        {
            // need transaction to keep ACID for creating Order and tickets

            return new Order
            {
                Id = 1,
                EventId = 1,
                Quantity = 3,
                Status = OrderStatus.Cancelled,
                IsDeleted = false,
                TotalPrice = 100,
                UserId = GetUserId(),
                UpdatedTime = DateTime.Now,
                CreatedTime = DateTime.Now,
            };
        }
    }
}
